

//数组的常用方法 
/**
 *  fill
 * forEach() 方法
 * filter()
 * map() 方法
 *  reduce() 方法
 * some
 * find
 * sort
 * copyWithin
 * every
 */


/**
 * fill
 */
let arr1 = []
let arr2 = new Array(10);
arr2.fill(1);
console.log(arr2);

/**
 * forEach 
 * */
let arr3 = [10, 20, 30, 40]
/**
 * 
 * @param {*} p1  代表循环到第几个的 值     10      20      30     40
 * @param {*} p2  代表循环到第几个的索引     0      1        2       3
 * @param {*} p3  原数组对象         [10, 20, 30, 40]  、 [10, 20, 30, 40]、[10, 20, 30, 40]、[10, 20, 30, 40]
 */


// arr3.forEach(function (item, index, originArr) {
//     console.log(`i=${index}, item:${item}`);
// })

arr3.forEach((item) => {
    console.log(` item:${item}`);
})


let nums = [10, 11, 13, 15, 16, 18];

let newArr1 = nums.filter((item) => {
    return item % 2 == 0
})
console.log("newArr1", newArr1);

let newArr2 = nums.filter((item) => {
    return item > 15
})
console.log("newArr2", newArr2);



/**
 * map 对数组进行加工
 */

let users = [
    { name: '张飞', age: 18, salary: 5800 },
    { name: '刘备', age: 58, salary: 9800 },
    { name: '关于', age: 48, salary: 7800 },
]
console.log("users1 ", users);

users.map(item => {
    item.salary = item.salary + 100
    return item
})
console.log("users2 ", users);



// users.map(item => {
//     console.log("item", item)
//     let result = item.salary + 100
//     return 100
// })

// console.log("users3 ", users);


let array3 = [2, 4, 6, 8]


let total = array3.reduce((p1, current, index) => {
    console.log("p1, current, index", p1, current);
    return p1 + current;
})

console.log("total", total);


/***
 *    
 *      p1, current, index  
 *       2    4        1        return  p1+current  2+4= 6
 *       6    6        2        return 6 + 6 
 *       12    8        3
 */


let array4 = [80, 59, 46]
let success1 = array4.some((item) => item > 60);

let success2 = array4.every((item) => item > 60);

console.log(success1)
console.log(success2)

let unsortNums = [100, 89, 92, 77, 87]

console.log("unsortNums.sort() ", unsortNums.sort());
console.log("unsortNums.sort( func) ", unsortNums.sort((numa, numb) => {
    return numa - numb
}));











